package controle.gui.principal;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

import controle.gui.cadastro.FEmpresa;
import controle.gui.cadastro.Socio;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.text.ParseException;
import javax.swing.JSeparator;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.KeyStroke;
import java.awt.event.KeyEvent;
import java.awt.event.InputEvent;
import javax.swing.JToolBar;
import javax.swing.JButton;

public class JPaiPrincipal extends JFrame {
	private static JPaiPrincipal pai;
	public static JPaiPrincipal getInstancia(){
		
		if(pai==null){
			
			pai=new JPaiPrincipal();
		}
		return pai;
	}
	
	public static JDesktopPane getDesktop(){
		return getInstancia().desktopPane;
		
		
	}
	
	JDesktopPane desktopPane;
	private JPanel contentPane;
	private JMenuItem mntmScio;

	/*
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					//JPaiPrincipal frame = new JPaiPrincipal();
					getInstancia().setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public JPaiPrincipal() {
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 1280, 800);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnNewMenu = new JMenu("Arquivo");
		menuBar.add(mnNewMenu);
		
		JMenuItem mntmNewMenuItem = new JMenuItem("Empresa");
		mntmNewMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JInternalFrame frame = new JInternalFrame("Cadastro Empresa",true,true,true,true);
				FEmpresa n1;
				try {
					n1 = new FEmpresa();
					
					desktopPane.add(n1,BorderLayout.CENTER);
					
					
					n1.setVisible(true);
					//n1.pack();
					
				} catch (ParseException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
				
			}
		});
		
		mnNewMenu.add(mntmNewMenuItem);
		
		mntmScio = new JMenuItem("Sócio");
	mntmScio.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Socio frameSocio;
				try {
					frameSocio = new Socio();
					JPaiPrincipal.getDesktop().add(frameSocio);
					frameSocio.setVisible(true);
				} catch (ParseException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
				
	/*		JInternalFrame frameSocio = new JInternalFrame("Cadastro Socio",true,true,true,true);
				Socio n1;
				try {
					n1 = new Socio();
					desktopPane.add(n1,BorderLayout.CENTER);
					
					
					n1.setVisible(true);
				} catch (ParseException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}*/
				
				
				//n1.pack();
				
				
			}
		});
		mnNewMenu.add(mntmScio);
		
		JMenu mnEndereco = new JMenu("Endereco");
		mnNewMenu.add(mnEndereco);
		
		JMenuItem mntmEstado = new JMenuItem("Estado");
		mnEndereco.add(mntmEstado);
		
		JMenuItem mntmCidade = new JMenuItem("Cidade");
		mnEndereco.add(mntmCidade);
		
		JSeparator separator = new JSeparator();
		mnNewMenu.add(separator);
		
		JMenuItem mntmSair = new JMenuItem("Sair");
		mntmSair.setMnemonic(KeyEvent.VK_1);
		mntmSair.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.SHIFT_MASK));
		mntmSair.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				System.exit(0);
			}
		});
		mnNewMenu.add(mntmSair);
		
		JMenu mnNewMenu_1 = new JMenu("Listagem");
		menuBar.add(mnNewMenu_1);
		
		JMenuItem mntmEmpresas = new JMenuItem("Empresas");
		mnNewMenu_1.add(mntmEmpresas);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		desktopPane = new JDesktopPane();
		contentPane.add(desktopPane, BorderLayout.CENTER);
		
		JToolBar toolBar = new JToolBar();
		contentPane.add(toolBar, BorderLayout.NORTH);
		
		JButton btnNewButton = new JButton("New button");
		toolBar.add(btnNewButton);
	}
	public void criarJanela()
	{
		
		
	}
}
